From e76ad352ea8133c229eddcbc5cc4cfe7c48c7a9b Mon Sep 17 00:00:00 2001 From: robertl Date: Mon, 5 Jan 2004 20:08:10 +0000 Subject: [PATCH] A number of changes throughout to support formats like GPX and Mapsource that can have more than one of (waypoints, tracks, routes) in one file. This doesn't get it for every format (or even for MPS output) but it helps some of our cases... --- gpsbabel/defs.h | 1 + gpsbabel/gpilots.c | 2 +- gpsbabel/gpx.c | 23 ++++++------------- gpsbabel/mapsource.c | 53 ++++++++++++++++++-------------------------- gpsbabel/psitrex.c | 4 ++-- gpsbabel/route.c | 29 +++++++++++++++++++++--- gpsbabel/waypt.c | 5 ++--- 7 files changed, 60 insertions(+), 57 deletions(-) diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index 45cad67fe..dc344205d 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -218,6 +218,7 @@ void route_add (waypoint *); void route_add_wpt(route_head *rte, waypoint *wpt); void route_del_wpt(route_head *rte, waypoint *wpt); void route_add_head(route_head *rte); +void track_add_head(route_head *rte); void route_disp_all(route_hdr, route_trl, waypt_cb); void route_free (route_head *); void route_flush( queue *); diff --git a/gpsbabel/gpilots.c b/gpsbabel/gpilots.c index 21660b015..62eabf543 100644 --- a/gpsbabel/gpilots.c +++ b/gpsbabel/gpilots.c @@ -219,7 +219,7 @@ data_read(void) */ case 101: track_head = route_head_alloc(); - route_add_head(track_head); + track_add_head(track_head); track_head->rte_name = xstrndup(rec->wpt.CustTrkHdr.name, sizeof(rec->wpt.CustTrkHdr.name)); sz = be_read32(&rec->wpt.CustTrkHdr.number); tp = (Custom_Trk_Point_Type *) ((char *) pdb_rec->data + sizeof(rec->wpt.CustTrkHdr)); diff --git a/gpsbabel/gpx.c b/gpsbabel/gpx.c index 14e71db72..f425b4ee0 100644 --- a/gpsbabel/gpx.c +++ b/gpsbabel/gpx.c @@ -355,7 +355,7 @@ gpx_start(void *data, const char *el, const char **attr) break; case tt_trk: trk_head = route_head_alloc(); - route_add_head(trk_head); + track_add_head(trk_head); in_trk++; break; case tt_trkpt: @@ -1148,7 +1148,7 @@ gpx_waypt_pr(const waypoint *waypointp) fprintf(ofd, "\n"); } } - if (waypointp->altitude) { + if (waypointp->altitude != unknown_alt) { fprintf(ofd, "\n%f\n\n", waypointp->altitude); } @@ -1220,7 +1220,7 @@ gpx_track_tlr(const route_head *rte) static void gpx_track_pr() { - route_disp_all(gpx_track_hdr, gpx_track_tlr, gpx_track_disp); + track_disp_all(gpx_track_hdr, gpx_track_tlr, gpx_track_disp); } static void @@ -1327,19 +1327,10 @@ gpx_write(void) fprintf(ofd, "xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd\">\n"); gpx_write_time( now, "time" ); - switch(global_opts.objective) { - case trkdata: - gpx_track_pr(); - break; - case rtedata: - gpx_route_pr(); - break; - case wptdata: - waypt_disp_all(gpx_waypt_pr); - break; - default: - break; - } + + waypt_disp_all(gpx_waypt_pr); + gpx_track_pr(); + gpx_route_pr(); fprintf(ofd, "\n"); } diff --git a/gpsbabel/mapsource.c b/gpsbabel/mapsource.c index 3f015f91c..13ea5ddd8 100644 --- a/gpsbabel/mapsource.c +++ b/gpsbabel/mapsource.c @@ -1221,7 +1221,7 @@ mps_track_r(FILE *mps_file, int mps_ver, route_head **trk) track_head = route_head_alloc(); track_head->rte_name = xstrdup(trkname); - route_add_head(track_head); + track_add_head(track_head); *trk = track_head; while (trk_count--) { @@ -1416,7 +1416,7 @@ mps_read(void) char recType; int reclen; - int skipMe; + int morework; mps_ver_in = 0; /* although initialised at declaration, what happens if there are two mapsource input files? */ @@ -1426,57 +1426,46 @@ mps_read(void) printf("static icon_mapping_t icon_table[] = {\n"); #endif + morework = 1; + while (morework && !feof(mps_file_in)) { - while (!feof(mps_file_in)) { - - /* skip over this record, unless.... */ - skipMe = 1; /* Read record length of next section */ fread(&reclen, 4, 1, mps_file_in); reclen = le_read32(&reclen); /* Read the record type "flag" in - using fread in case in the future need more than one char */ fread(&recType, 1, 1, mps_file_in); - - if (recType == 'W') { + switch (recType) { + case 'W': /* Waypoint record */ /* With routes, we need the waypoint info that reveals, for example, the symbol type */ - if ((global_opts.objective == wptdata) || (global_opts.objective == rtedata)) { - mps_waypoint_r(mps_file_in, mps_ver_in, &wpt); + mps_waypoint_r(mps_file_in, mps_ver_in, &wpt); #ifdef DUMP_ICON_TABLE - printf("\t{ %4u, \"%s\" },\n", icon, wpt->shortname); + printf("\t{ %4u, \"%s\" },\n", icon, wpt->shortname); #endif - skipMe = 0; - } - } + break; - if (recType == 'R') { + case 'R': /* Route record */ - if (global_opts.objective == rtedata) { - mps_route_r(mps_file_in, mps_ver_in, &rte); - skipMe = 0; - } - } + mps_route_r(mps_file_in, mps_ver_in, &rte); + break; - if (recType == 'T') { + case 'T': /* Track record */ - if (global_opts.objective == trkdata) { - mps_track_r(mps_file_in, mps_ver_in, &trk); - skipMe = 0; - } - } + mps_track_r(mps_file_in, mps_ver_in, &trk); + break; - if (recType == 'V') { + case 'V': /* Mapset record */ mps_mapsetname_r(mps_file_in, mps_ver_in); - skipMe = 0; /* Last record in the file */ + morework = 0; break; - } - - if (skipMe == 1) { + default: + /* Unknown record type. Skip over it. */ fseek(mps_file_in, reclen, SEEK_CUR); } + } /* while (!feof(mps_file_in)) */ #ifdef DUMP_ICON_TABLE @@ -1669,7 +1658,7 @@ mps_write(void) fread(&recType, 1, 1, mps_file_temp); } } - route_disp_all(mps_trackhdr_w_wrapper, mps_noop, mps_trackdatapoint_w_wrapper); + track_disp_all(mps_trackhdr_w_wrapper, mps_noop, mps_trackdatapoint_w_wrapper); } if (mpsmergeout) { diff --git a/gpsbabel/psitrex.c b/gpsbabel/psitrex.c index a71527ed8..b3f99e199 100755 --- a/gpsbabel/psitrex.c +++ b/gpsbabel/psitrex.c @@ -601,7 +601,7 @@ psit_track_r(FILE *psit_file, route_head **trk) track_head->rte_name = xstrdup(trkname); } trk_num++; - route_add_head(track_head); + track_add_head(track_head); } thisWaypoint->creation_time = dateTime; @@ -795,7 +795,7 @@ psit_write(void) route_disp_all(psit_routehdr_w_wrapper, psit_noop, psit_waypoint_w_wrapper); } if (global_opts.objective == trkdata) { - route_disp_all(psit_trackhdr_w_wrapper, psit_noop, psit_trackdatapoint_w_wrapper); + track_disp_all(psit_trackhdr_w_wrapper, psit_noop, psit_trackdatapoint_w_wrapper); } mkshort_del_handle(mkshort_handle); diff --git a/gpsbabel/route.c b/gpsbabel/route.c index 6c85a3bf8..3841d3521 100644 --- a/gpsbabel/route.c +++ b/gpsbabel/route.c @@ -21,6 +21,7 @@ #include "defs.h" static queue my_route_head; +static queue my_track_head; static int rte_head_ct; static int rte_waypts; @@ -28,6 +29,7 @@ void route_init(void) { QUEUE_INIT(&my_route_head); + QUEUE_INIT(&my_track_head); } unsigned int @@ -61,6 +63,13 @@ route_add_head(route_head *rte) rte_head_ct++; } +void +track_add_head(route_head *rte) +{ + ENQUEUE_TAIL(&my_track_head, &rte->Q); + QUEUE_INIT(&rte->waypoint_list); +} + void route_add_wpt(route_head *rte, waypoint *wpt) { @@ -118,11 +127,11 @@ route_reverse(const route_head *rte_hd) } } -void -route_disp_all(route_hdr rh, route_trl rt, waypt_cb wc) +void +common_disp_all(queue *qh, route_hdr rh, route_trl rt, waypt_cb wc) { queue *elem, *tmp; - QUEUE_FOR_EACH(&my_route_head, elem, tmp) { + QUEUE_FOR_EACH(qh, elem, tmp) { const route_head *rhp; rhp = (route_head *) elem; if (rh) (*rh)(rhp); @@ -130,6 +139,19 @@ route_disp_all(route_hdr rh, route_trl rt, waypt_cb wc) if (rt) (*rt)(rhp); } } + +void +route_disp_all(route_hdr rh, route_trl rt, waypt_cb wc) +{ + common_disp_all(&my_route_head, rh, rt, wc); +} + +void +track_disp_all(route_hdr rh, route_trl rt, waypt_cb wc) +{ + common_disp_all(&my_track_head, rh, rt, wc); +} + void route_flush(queue *head) { @@ -146,5 +168,6 @@ void route_flush_all() { route_flush(&my_route_head); + route_flush(&my_track_head); } diff --git a/gpsbabel/waypt.c b/gpsbabel/waypt.c index 879a291f9..5e2831db6 100644 --- a/gpsbabel/waypt.c +++ b/gpsbabel/waypt.c @@ -192,10 +192,9 @@ waypt_flush( queue *head ) { queue *elem, *tmp; - queue *q; QUEUE_FOR_EACH(head, elem, tmp) { - q = dequeue(elem); - waypt_free((waypoint *) q); + waypoint *q = (waypoint *) dequeue(elem); + waypt_free(q); } } -- 2.30.2